VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "WIN32 demo (ICODE2)"
   ClientHeight    =   6900
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6600
   BeginProperty Font 
      Name            =   "宋体"
      Size            =   9
      Charset         =   134
      Weight          =   700
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   6900
   ScaleWidth      =   6600
   StartUpPosition =   2  'CenterScreen
   WhatsThisHelp   =   -1  'True
   Begin VB.TextBox Text5 
      Height          =   375
      Left            =   3240
      TabIndex        =   19
      Text            =   "1"
      Top             =   2040
      Width           =   735
   End
   Begin VB.TextBox Text4 
      Height          =   375
      Left            =   1320
      TabIndex        =   17
      Text            =   "4"
      Top             =   2040
      Width           =   735
   End
   Begin VB.OptionButton Option2 
      Caption         =   "Multy"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   3240
      TabIndex        =   15
      Top             =   1200
      Width           =   1215
   End
   Begin VB.OptionButton Option1 
      Caption         =   "Single"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   2280
      TabIndex        =   14
      Top             =   1200
      Value           =   -1  'True
      Width           =   1215
   End
   Begin VB.TextBox Text3 
      Height          =   375
      Left            =   1080
      TabIndex        =   13
      Text            =   "4"
      Top             =   5280
      Width           =   735
   End
   Begin VB.CommandButton Command5 
      Caption         =   "Clear"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   5040
      TabIndex        =   11
      Top             =   4680
      Width           =   1455
   End
   Begin VB.TextBox Text2 
      Height          =   1935
      Left            =   360
      MultiLine       =   -1  'True
      TabIndex        =   10
      Top             =   2760
      Width           =   6135
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   3840
      TabIndex        =   9
      Text            =   "11223344"
      Top             =   5280
      Width           =   2415
   End
   Begin VB.CheckBox Check1 
      Caption         =   "USB"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   360
      TabIndex        =   8
      Top             =   120
      Value           =   1  'Checked
      Width           =   1935
   End
   Begin VB.ComboBox Combo1 
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   360
      ItemData        =   "sample.frx":0000
      Left            =   4320
      List            =   "sample.frx":0002
      Style           =   2  'Dropdown List
      TabIndex        =   7
      Top             =   600
      Width           =   1695
   End
   Begin VB.CommandButton Command7 
      Caption         =   "Read block"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   4560
      TabIndex        =   5
      Top             =   2040
      Width           =   1815
   End
   Begin VB.CommandButton Command6 
      Caption         =   "Beep"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   360
      TabIndex        =   4
      Top             =   1200
      Width           =   1455
   End
   Begin VB.CommandButton Command4 
      Caption         =   "Exit"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   5040
      TabIndex        =   3
      Top             =   6000
      Width           =   1455
   End
   Begin VB.CommandButton Command3 
      Caption         =   "Write block"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   1920
      TabIndex        =   2
      Top             =   5280
      Width           =   1815
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Chose card"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   4560
      TabIndex        =   1
      Top             =   1200
      Width           =   1815
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Initial"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   360
      TabIndex        =   0
      Top             =   600
      Width           =   1455
   End
   Begin VB.Label Label4 
      Caption         =   "Block number"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   615
      Left            =   2280
      TabIndex        =   18
      Top             =   1920
      Width           =   975
   End
   Begin VB.Label Label3 
      Caption         =   "Start block"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   615
      Left            =   360
      TabIndex        =   16
      Top             =   1920
      Width           =   975
   End
   Begin VB.Label Label2 
      Caption         =   "Block"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   360
      TabIndex        =   12
      Top             =   5280
      Width           =   735
   End
   Begin VB.Label Label1 
      Caption         =   "Chose device"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   2280
      TabIndex        =   6
      Top             =   600
      Width           =   2055
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim snr, tagtype As Long
Dim data32(16) As Byte
Dim cardmode As Integer
Dim loadmode As Integer
Dim rlen(2) As Byte
Dim UID(256) As Byte
Dim revbuf(3000) As Byte
Dim revhexbuf(5000) As Byte
Dim buf2str As String



Private Sub Msg(srvstr As String)



Text2.Text = vbCrLf + Text2.Text 'Chr(10) + Chr(13) + Text2.Text
Text2.Text = srvstr + Text2.Text

End Sub



Private Sub Combo1_Click()

Dim index As Integer

'Chose special device

If icdev > 0 Then

index = Combo1.ListIndex
icdev = ihdevs(index)

End If

End Sub

Private Sub Combo2_Click() 'Chose current card type

cardtype = Combo2.ListIndex

Select Case cardtype
Case 0
st = fw_setcpu(icdev, 12)
Case 1
'st = fw_setcpu(icdev, &HD)
Case 2
'st = fw_setcpu(icdev, &HE)
Case 3
'st = fw_setcpu(icdev, &HF)

End Select

If st <> 0 Then
  Msg ("setup card error")
  Exit Sub
End If

Msg ("setup card success")

End Sub

Private Sub Command1_Click()

Dim tmphdev As Integer
Dim i As Integer
Dim strdev As String

Combo1.Clear

If Check1.value = 1 Then

'loop to get handle of ecah reader when case of USB

i = 0

Do
  tmphdev = fw_init(100, 0)
  
  strdev = "Reader"
  
  If tmphdev > 0 Then
  ihdevs(i) = tmphdev
  strdev = strdev + Str(i)
  
  Combo1.AddItem strdev
  Combo1.Text = strdev
  
  End If
  
  i = i + 1
  
Loop Until tmphdev < 0 And i < 100


Else

'Case of serial port
tmphdev = fw_init(0, 115200) 'COM1,baut rate 115200

If tmphdev > 0 Then
Combo1.AddItem "Reader 0"
Combo1.Text = "Reader 0"
ihdevs(0) = tmphdev

End If

End If 'If Check1.value = 1 Then

icdev = ihdevs(0)

If icdev > 0 Then
Combo1.ListIndex = 0
End If

  

If icdev < 0 Then
   MsgBox "Call fw_init() function error"
Else
   MsgBox "Call fw_init() function success!"
End If

 st = fw_config_card(icdev, &H31)

End Sub



Private Sub Command2_Click() 'select card

If Option1.value Then
  st = fw_inventory(icdev, &H36, 0, 0, rlen(0), UID(0))
  ElseIf Option2.value Then
  st = fw_inventory(icdev, &H16, 0, 0, rlen(0), UID(0))
  Else
  MsgBox ("Select Single card or multy card")
  Exit Sub
End If

If st <> 0 Then
  Msg ("select card error")
  Exit Sub
End If

  Msg ("select card success")
  

  
End Sub

Private Sub Command3_Click() 'sent command

Dim strcmd() As Byte
Dim cmdbuf(3000) As Byte
Dim slen As Integer
Dim startblk As Integer

startblk = CInt(Text3.Text)

strcmd = StrConv(Text1.Text, vbFromUnicode)

slen = Len(Text1.Text)
  
st = a_hex(cmdbuf(0), strcmd(0), slen / 2)

st = fw_writeblock(icdev, &H22, startblk, 1, UID(0), 4, cmdbuf(0))

If st <> 0 Then

Msg ("write error")

Else

Msg ("write success")

End If



End Sub

Private Sub Command4_Click()
End
End Sub



Private Sub Command5_Click()


Text2.Text = ""



End Sub

Private Sub Command6_Click()


st = fw_beep(ByVal icdev, 10)
If st <> 0 Then
      Msg ("Call fw_beep() function error")
      Exit Sub
End If
Msg ("Call fw_beep() function success")
DoEvents

End Sub

Private Sub Command7_Click()  'read card
Dim startblk As Integer
Dim cntblk  As Integer
Dim intx As Integer


startblk = CInt(Text4.Text)
cntblk = CInt(Text5.Text)

st = fw_select_uid(icdev, &H22, UID(0))
If st <> 0 Then
  Msg ("Call funciton fw_select_uid error")
  Exit Sub
End If
  'Msg ("Call fw_select_uid success")
  
st = fw_reset_to_ready(icdev, &H22, UID(0))
If st <> 0 Then
  Msg ("Call function fw_reset_to_ready error")
  Exit Sub
End If
'Msg ("Call function fw_reset_to_ready success")

st = fw_get_securityinfo(icdev, &H22, &H4, &H2, UID(0), rlen(0), revbuf(0)) 'get safe information
If st <> 0 Then
  Msg ("Call function fw_get_securityinfo error")
  Exit Sub
End If
'Msg ("Call funciton fw_get_securityinfo success")
  

st = fw_readblock(icdev, &H22, startblk, cntblk, UID(0), rlen(0), revbuf(0))
If st <> 0 Then

  Msg ("read blocks error")
  Exit Sub
  
End If
Msg ("read blocks success")

Erase revhexbuf 'clear

'show data
  hex_a revhexbuf(0), revbuf(0), 2 * rlen(0)
  
  
  buf2str = StrConv(revhexbuf, vbUnicode)
  
  Msg ("DATA: " + buf2str)


End Sub

Private Sub Form_Load()

Erase ihdevs
icdev = -1



End Sub

Private Sub Form_Unload(Cancel As Integer)
quit
End Sub

